package com.learn.sb.reids.demo.pubsub;

import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;

/**
 * Redis 消息监听器
 * 发布订阅模式里的 订阅者
 */
@Component
public class RedisMessageListener implements MessageListener {

	@Override
	public void onMessage(Message message, @Nullable byte[] pattern) {
		// 消息体
		String body = new String(message.getBody());
		// 渠道名称
		String topic = new String(pattern);
		System.out.println("topic:" + topic + ", body:" + body);
	}
}
